package thread;

import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @Description: null
 * @Project: testDemo
 * @Author: hjibo
 * @CreateDate: 2019/1/24 11:24
 * @ModificationHistory: （who whatTime doWhat）
 */
public class ThreadDemo5 implements Runnable {
    private ReadWriteLock lock = new ReentrantReadWriteLock();

    @Override
    public void run() {
        Thread.currentThread().setName("ThreadDemo5线程");
        try {
            lock.writeLock().lock();
            System.out.println("线程："+Thread.currentThread().getName()+",获取了写锁");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.writeLock().unlock();
        }
    }
}
